﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.guide {
    import Modules.guide.actions.*;

    public class GuideSequence {

        public var m_name:String = "";
        public var m_trigger:String;
        public var m_actions:Array;
        public var m_actionExec:GuideActionExecutor;
        private var m_currentAction:int = -1;
        protected var m_completed:Boolean = false;
        protected var m_active:Boolean = false;
        protected var m_guide:Guide = null;

        public function GuideSequence(_arg1:Guide){
            this.m_guide = _arg1;
            this.m_actions = new Array();
            this.m_actionExec = new GuideActionExecutor();
        }
        public function setActive(_arg1:Boolean):void{
            this.m_active = _arg1;
        }
        public function isActive():Boolean{
            return (this.m_active);
        }
        public function isComplete():Boolean{
            return (this.m_completed);
        }
        public function getActionExec():GuideActionExecutor{
            return (this.m_actionExec);
        }
        public function addAction(_arg1:GuideAction):void{
            if (_arg1 != null){
                this.m_actions.push(_arg1);
            };
        }
        public function nextAction():GuideAction{
            this.m_currentAction++;
            if (this.m_currentAction < this.m_actions.length){
                return (this.m_actions[this.m_currentAction]);
            };
            return (null);
        }
        public function currentAction():GuideAction{
            return (this.m_actions[this.m_currentAction]);
        }
        public function update(_arg1:Number):void{
            var _local2:GuideAction;
            if (!this.m_active){
                return;
            };
            if (this.m_actionExec.getState() == null){
                _local2 = this.nextAction();
                if (_local2 != null){
                    GlobalEngine.log("Guide", ((("New action: " + this.m_name) + " / ") + _local2));
                    this.m_actionExec.addState(_local2);
                } else {
                    this.m_completed = true;
                    this.m_active = false;
                };
            };
            this.m_actionExec.update(_arg1);
        }
        public function cleanup():void{
            this.m_actionExec.removeAllStates();
        }
        public function start():void{
            this.m_active = true;
            var _local1:GuideAction = this.nextAction();
            if (_local1 != null){
                this.m_actionExec.addState(_local1);
            } else {
                this.resetActionIndex();
            };
        }
        public function stop(_arg1:Boolean=false):void{
            if (_arg1){
                this.m_guide.removeDialogs();
                this.m_guide.removeMask();
                this.m_guide.removeArrows();
                this.m_guide.removeGuideTiles();
            };
            this.m_active = false;
            this.m_actionExec.removeAllStates();
            this.resetActionIndex();
        }
        public function createFromXml(_arg1:XML):Boolean{
            var name:* = null;
            var trigger:* = null;
            var xml:* = _arg1;
            if (xml == null){
                return (false);
            };
            try {
                name = xml.@name;
                trigger = xml.@trigger;
                if (name.length > 0){
                    this.m_name = name;
                } else {
                    return (false);
                };
                if (trigger.length > 0){
                    this.m_trigger = trigger;
                } else {
                    return (false);
                };
            } catch(err:Error) {
                return (false);
            };
            return (true);
        }
        private function resetActionIndex():void{
            this.m_currentAction = -1;
        }

    }
}//package Modules.guide 
